home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / GRAPHICS.SWG / 0060_Poly Drawing.pas < prev    next >
Pascal/Delphi Source File  |  1994-01-27  |  4KB  |  114 lines

  1. (*
  2. > It's not that slow. I can get about 60 good-sized
  3. > poly's in a second on my dinky 386sx-20. It also does
  4. > ^ ^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^
  5. > I don't know what a good speed is for polyfills, but this sounds quite
  6. > good! Thanks heaps (and stacks?  :^) for the post!
  7.  
  8. You're welcome. I just now converted it to 99% assembler, 386+, just gotta
  9. test it out.
  10.  
  11. > One question to follow:
  12.  
  13. > {  fillWord(mem[$A000:0],64000,0);  {clear}
  14. > ^^^                                ^stick closer ("}") here
  15.  
  16. > You'll probably recognize the above as the main routine of the polygon
  17. > fill snippet (the tester part).  Please note the part I under-careted
  18. > (or -caretted).  There is no closing comment before the next opening
  19. > comment. Should the closer be placed where indicated by me?  Or
  20. > was the opener a typo?
  21. > Not a big deal, but I want this to work so I can be impressed!  :^)
  22.  
  23. It works like that, at least in TP/BP. The open comment in effect keeps the
  24. compiler from ever seeing the next open brace. So the second brace's closing
  25. brace actually closes the first one. A trick I learned since I started at
  26. deltaComm. No, I actually wanted that commented out, because clearing the
  27. screen between each one slows it down.
  28.  
  29. Actually, I noticed a strange behaviour in the fill, where if you have one
  30. vertex = (x,y) and the next vertex = (x+40,y+1) then you'll end up with a dot
  31. on one line and the next line entirely filled. Not what was intended. I came up
  32. with a fix for it:
  33.  
  34. It basically just centers the stairstep zigzag by adding half a step before it
  35. starts.
  36. *)
  37.  
  38. function lSar(L:longint):longint;assembler;asm
  39.  db $66; mov ax,L       {mov eax,L}
  40.  db $66; sar ax,1       {sar eax,1}
  41.  db $66,$0F,$A4,$C2,$10 {shld edx,eax,16}
  42.  end;
  43.  
  44.  
  45. procedure draw(color:byte);
  46. var i,l,r,lv,rv,top,bottom,topVert:integer; var lstep,lpos,rstep,rpos:fixed;
  47. var ldest,rdest:tPoint; begin
  48.  {find top and bottom vertices}
  49.  topVert:=numVerts-1;
  50.  top:=vertex[topVert].y; bottom:=top;
  51.  for i:=numVerts-2 downto 0 do
  52.    if (vertex[i].Y < top) then begin
  53.     top:=vertex[i].Y;
  54.     topVert:=i;
  55.     end
  56.    else if (vertex[i].Y > bottom) then
  57.     bottom:=vertex[i].Y;
  58.  if bottom>maxY then bottom:=maxY;       {clip bottom}
  59.  if top>bottom then exit;
  60.  lv:=topVert; rv:=topVert;
  61.  ldest:=vertex[topVert]; rdest:=ldest;
  62.  i:=top;
  63.  repeat
  64.   if i<bottom then begin
  65.  
  66. {
  67. ^^^^^^^^^^^^^^^^^^^^^^^^^ keep from getting wierd effects from the
  68.                           adjustment on the last row.
  69. }
  70.    if i>=ldest.y then begin
  71.     lpos.f:=0; lpos.i:=ldest.x;
  72.     dec(lv); if lv<0 then lv:=numVerts-1;
  73.     ldest:=vertex[lv];
  74.     if ldest.y=i then begin
  75.       if ldest.x<lpos.i then lpos.i:=ldest.x;
  76.       lstep.l:=0;
  77.       end
  78.     else begin
  79.       lstep.l:=fixedDiv(ldest.x-lpos.i,ldest.y-i);
  80.       inc(lpos.l,lSar(lstep.l));
  81.  
  82.       ^^^^^^^^^^^^^^^^^^^^^^^^^^  Center the stairstep pattern
  83.  
  84.       end;
  85.     end;
  86.    if i>=rdest.y then begin
  87.     rpos.f:=0; rpos.i:=rdest.x;
  88.     inc(rv); if rv>=numVerts then rv:=0;
  89.     rdest:=vertex[rv];
  90.     if rdest.y=i then begin
  91.       if rdest.x>rpos.i then rpos.i:=rdest.x;
  92.       rstep.l:=0;
  93.       end
  94.     else begin
  95.       rstep.l:=fixedDiv(rdest.x-rpos.i,rdest.y-i);
  96.       inc(rpos.l,lSar(rStep.l));
  97.  
  98.       ^^^^^^^^^^^^^^^^^^^^^^^^^^  Center the stairstep pattern
  99.  
  100.       end;
  101.     end;
  102.    end;
  103.   if i>=minY then begin                             {clip top}
  104.    if lpos.i>minX then l:=lpos.i else l:=minX;      {clip left}
  105.    if rpos.i<maxX then r:=rpos.i else r:=maxX;      {clip right}
  106.    if (l<=r) then
  107.     fillWord(mem[$A000:i*320+l],r-l+1,color);
  108.    end;
  109.   inc(lpos.l,lstep.l);
  110.   inc(rpos.l,rstep.l);
  111.   inc(i);
  112.   until i>bottom;
  113.  end;
  114.